import java.util.Arrays;

class Student implements Comparable<Student>{
    public String name;
    public int age;
    public int score;

    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    /*@Override
    public int compareTo(Student o) {
        if (this.age > o.age){
            return 1;
        }else if(this.age < o.age){
            return -1;
        }else {
            return 0;
        }
    }*/

    @Override
    public int compareTo(Student o) {
        if (this.name.compareTo(o.name)>0){//注意！这里的comparableTo是String类中的！！！
            return 1;
        }else if(this.name.compareTo(o.name)<0){
            return -1;
        }else {
            return 0;
        }
    }
}
public class Test {
    //这里是用“冒泡排序”来模拟了sort方法的排序
    public static void sort(Comparable[] array){
        for (int i = 0;i < array.length-1;i++){
            for (int j = 0;j < array.length-1-i;j++){
                if (array[j].compareTo(array[j+1])>0){
                    Comparable tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                }
            }
        }
    }
    public static void main(String[] args) {//对这个数组排序怎么排？
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan", 19, 10);
        students[1] = new Student("lisi", 24, 59);
        students[2] = new Student("wangwu", 30, 69);
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }
}
